import QtQuick 2.9
import QtQuick.Window 2.9
import com.fs.Controls 1.0

Window {
    id: win
    visible: true
    flags: Qt.Window|Qt.FramelessWindowHint
    visibility: Window.FullScreen

    Image {
        smooth: true
        source: 'window.png'
        width: parent.width
        height: parent.height
    }

    ListView {
        id:listPic
        width: parent.width
        height: parent.height
        model: imageModel
        delegate: imageDelegate
        orientation: ListView.Horizontal
        snapMode: ListView.SnapOneItem
        highlightRangeMode: ListView.StrictlyEnforceRange
        boundsBehavior: Flickable.StopAtBounds
        keyNavigationWraps: true
        Component.onCompleted:{
            control.PicRewrite.connect(updatePic)
        }
        function updatePic(strPath){
            imageModel.clear()
            if(strPath===""){
                return
            }
            var paths = strPath.split(',')
            for (var i=0;i<paths.length;i++){
                console.log(paths[i])
                imageModel.append({"path":paths[i]})
            }
        }
    }

    MyCharactor{
        text:control.doorNo
        anchors.fill: parent
        x:50
        y:200
    }

    Rectangle {
        id: rectQrcode
        width: 200
        height: 200
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.bottomMargin: 50
        anchors.leftMargin: 50
        color: "#00000000"
        Image{
            id: imgQrcode
            anchors.fill: parent
            anchors.centerIn: parent
            cache: false
        }
        Component.onCompleted:{
            control.QrcodeRewrite.connect(updateQrcode)
        }
        function updateQrcode(path){
            imgQrcode.source=""
            imgQrcode.source=path
        }
    }

    Component {
        id: imageDelegate
        Image {
            id: name
            source: path
            width:win.width
            height: win.height
        }
    }

    ListModel{
        id: imageModel

    }

    Timer {
        id: myTimer;
        interval: control.interval*1000;
        repeat: true;
        running: true;
        triggeredOnStart: true;
        onTriggered:
        {
//            console.log("当前page:"+listPic.currentIndex);cd
            if(imageModel.count==1){
                return
            }

            if(listPic.currentIndex==imageModel.count-1)
            {
                var n = imageModel.count - 1;
                var to =imageModel.count - n;
                imageModel.move(0,to,n);
                listPic.currentIndex = 1;

            }else{
                listPic.incrementCurrentIndex();
            }
//            console.log("after increase:"+listPic.currentIndex)
        }
    }
}
